package com.ruoyi.yx.wxpay;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.framework.web.service.VipRechargeService;
import com.ruoyi.framework.web.service.WeChatService;
import com.ruoyi.framework.web.service.WePayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api("微信支付Controller")
@RequestMapping("/api/wxpay/js")
public class WXPayController extends BaseController {

    @Autowired
    private WeChatService weChatService;

    @Autowired
    private WePayService wePayService;

    @Autowired
    private VipRechargeService vipRechargeService;

    /**
     * 支付通知
     */
    @PostMapping("/notify")
    @ApiOperation("支付通知")
    public ResponseEntity wxNotify(HttpServletRequest request, HttpServletResponse response, @RequestBody String notifyData)
    {

        ResponseEntity.BodyBuilder bodyBuilder = wePayService.wxNotify(request,notifyData);

        return bodyBuilder.build();
    }

    /**
     * 预支付
     */
    @PostMapping("/prepay")
    @ApiOperation("预支付")
    public R prepay(@RequestBody Long optionsId)
    {
        return wePayService.prepay(optionsId);
    }

    /**
     * 获取充值参数
     * @return
     * @throws Exception
     */
    @PostMapping("/rechargeOptions")
    @ApiOperation("获取充值参数")
    public R selectYxVipRechargeOptionsList()throws Exception{
        return vipRechargeService.selectYxVipRechargeOptionsList();
    }

    /**
     * 获取会员等级
     * @return
     * @throws Exception
     */
    @PostMapping("/userVipStatus")
    @ApiOperation("获取会员等级")
    public R userVipStatus()throws Exception{
        return vipRechargeService.userVipStatusR();
    }

}
